import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_slidable/flutter_slidable.dart';

import '../../home.dart';
import '../../../../routes/routes.dart';
import '../../../../models/models.dart';
import '../../../../shared/shared.dart';
import '../../../../widgets/widgets.dart';

class MessageCard extends GetView<HomeLogic> {
  final UserMessages userMessage;
  final int index;

  const MessageCard({Key? key, required this.userMessage, required this.index})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => Get.toNamed(Routes.chat, arguments: userMessage),
      child: Slidable(
        actionPane: const SlidableScrollActionPane(),
        actionExtentRatio: 0.25,
        secondaryActions: [
          IconSlideAction(
            caption: '标记为未读',
            color: ColorConstants.primaryColor,
            icon: Icons.chat,
            onTap: () => false,
          ),
          IconSlideAction(
            caption: '删除',
            color: Colors.red,
            icon: CupertinoIcons.delete,
            onTap: () => controller.userMessages.removeAt(index),
          )
        ],
        child: Column(
          children: [
            CommonWidget.line(),
            Row(
              children: [
                Container(
                    margin: const EdgeInsets.all(12),
                    child: Avatar(
                        imageURL: userMessage.profilePicture.toString())),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(userMessage.userName.toString(),
                          style: const TextStyle(
                              color: ColorConstants.themeColor, fontSize: 20)),
                      Text(userMessage.lastMessage.toString(),
                          style: const TextStyle(
                              color: ColorConstants.themeColor, fontSize: 14)),
                      Text(userMessage.dateNow.toString(),
                          style: const TextStyle(
                              color: ColorConstants.themeColor, fontSize: 12)),
                    ],
                  ),
                ),
                Container(
                  alignment: Alignment.center,
                  margin: const EdgeInsets.all(12),
                  width: 30,
                  height: 30,
                  decoration: const BoxDecoration(
                      // color: ColorConstants.primaryColor,
                      borderRadius: BorderRadius.all(Radius.circular(12))),
                )
              ],
            ),
            CommonWidget.line(),
          ],
        ),
      ),
    );
  }
}
